package argo.hot100.greedy;

public class MaxProfit {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length <= 1) {
            return 0;
        }

        int preMin = prices[0], maxGre = 0;

        for (int i = 1; i < prices.length; i++) {
            maxGre = Math.max(prices[i] - preMin, maxGre);
            preMin = Math.min(prices[i], preMin);
        }

        return maxGre;
    }

}
